package com.lagou.controller;

import com.lagou.domain.Department;
import com.lagou.domain.Employees;
import com.lagou.service.EmployeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/employees")
public class EmployeeController {

    @Autowired
    private EmployeesService employeesService;

    @RequestMapping("/findAll")
   public String findAll(Model model){

        List<Employees> allEmployees = employeesService.findAllEmployees();

//        for(Employees employees:allEmployees){
//
//            Date time =new Date(employees.getJoin_date());
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//            String timeFormat = sdf.format(time);
//            employees.setJoin_date(timeFormat);
//        }
        model.addAttribute("list",allEmployees);

       return "list";

   }

   @RequestMapping("/save")
   public String save(Employees employees){
        employeesService.newEmployee(employees);
        return "redirect:/employees/findAll";
   }





}
